﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Constructor
{
    public partial class ExemplarProperties : UserControl
    {
        public Frame Frame { get; set; }
        public ExemplarProperties()
        {
            InitializeComponent();            
        }
        public void Init(Frame f)
        {
            Visible = true;
            Frame = f;
            txt_name.Text = f.Name;
            flowLayoutPanel1.Controls.Clear();
            foreach (Slot s in f.AllSlots)
                flowLayoutPanel1.Controls.Add(new ExemplarSlot(s));
        }        
        private void txt_name_Leave(object sender, EventArgs e)
        {
            if (txt_name.Text.Trim() == "")
            {
                MessageBox.Show("Имя не может быть пустым");
                return;
            }
            Frame.Name = txt_name.Text.Trim();
            Frame.RepaintNode(true);
        }

        private void btn_random_Click(object sender, EventArgs e)
        {
            foreach (Control c in flowLayoutPanel1.Controls)
                (c as ExemplarSlot).KoreanRandom();
        }
        public void Hide()
        {
            Visible = false;
        }

        private void txt_name_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                txt_name_Leave(null, null);
            }
        } 
    }
}
